import cv2
from _00tools import cv_show
"""
@Project: pythonPro1
@Name: _05threshold.py
@Author: linxin_liu
@Date: 2022/10/12 16:51
"""
img0 = cv2.imread('D:/tools/image_operation/cat.png', cv2.IMREAD_GRAYSCALE)
# 输入灰度图，大于127的赋值为255，反之赋值为0。thresh为图。ret为阈值，就是这里的127。
ret, thresh0 = cv2.threshold(img0, 127, 255, cv2.THRESH_BINARY)
ret, thresh1 = cv2.threshold(img0, 127, 255, cv2.THRESH_BINARY_INV)
ret, thresh2 = cv2.threshold(img0, 127, 255, cv2.THRESH_TRUNC)
ret, thresh3 = cv2.threshold(img0, 127, 255, cv2.THRESH_TOZERO)
ret, thresh4 = cv2.threshold(img0, 127, 255, cv2.THRESH_TOZERO_INV)
# print(ret)
titles = ['origin', 'THRESH_BINARY', 'THRESH_BINARY_INV', 'THRESH_TRUNC', 'THRESH_TOZERO', 'THRESH_TOZERO_INV']
images = [img0, thresh0, thresh1, thresh2, thresh3, thresh4]
for i in range(6):
    cv_show(titles[i], images[i], 5000)
